/*
2021-8-8
https://www.acwing.com/problem/content/137/
*/ 
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
const int N=300010;
int s[N],q[N];

int main()
{
    int n,m;
    cin>>n>>m;
    
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        s[i]+=s[i-1];
    }
    
    int hh=0,tt=0;
    int res=-1e9;
    
    for(int i=1;i<=n;i++)
    {
        if(q[hh] < i-m) hh++;
        res=max(res,s[i]-s[q[hh]]);
        while(hh<=tt && s[i]<=s[q[tt]]) tt--;
        q[++tt]=i;
    }
    cout<<res<<endl;
    return 0;
}
